#include "Widget.h"
#include "PatientModel.h"
#include "PatientDelegate.h"
#include <QListView>
#include <QMessageBox>
#include "./ui_Widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    // ui->setupUi(this);

    this->setWindowTitle("ListView Test");
    // this->setFixedSize(600,800);

    QListView* view=new QListView(this);
    view->setMouseTracking(true);

    view->setSpacing(5);
    view->setFixedSize(500,700);
    view->setUniformItemSizes(true);//item设置为同一高度
    view->setGridSize(QSize(456,110));//设置宽高
    view->setEditTriggers(QAbstractItemView::NoEditTriggers);
    QString style=R"(
    QListView::item { height: 110px;width: 456px; }
    QScrollBar:vertical {
        background: transparent;
        width: 4px;
        margin: 0px 0px 0px 0px;
    }

    QScrollBar::handle:vertical {
        background: lightgray;
        min-height: 200px;
        width:4px;
        border-radius: 2px;
    }
    QSCrollBar::sub-line,QSCrollBar::add-line,
    QScrollBar::up-arrow,QScrollBar::down-arrow:vertical{
        height:0px;
    }

)";

    view->setStyleSheet(style);

    auto * model=new PatientModel();
    QString db_path="C:\\Users\\USER\\Desktop\\data.db";
    model->LoadFromDatabase(db_path);

    auto* delegate=new PatientDelegate();

    //绑定信号槽
    QObject::connect(delegate, &PatientDelegate::On_EditPersonData_Btn, [&](int row){
        QMessageBox::information(this, "按钮1", QString("你点击了第 %1 行的按钮1").arg(row));
    });

    QObject::connect(delegate, &PatientDelegate::On_DeletePerson_Btn, [&](int row){
        QMessageBox::information(this, "按钮2", QString("你点击了第 %1 行的按钮2").arg(row));
    });

    view->setModel(model);
    view->setItemDelegate(delegate);



}

Widget::~Widget()
{
    delete ui;
}
